package com.css.upms.biz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.css.common.core.utils.R;
import com.css.upms.api.entity.SysOptLog;
import com.css.upms.api.vo.OptLogVO;
import com.css.upms.biz.service.SysOptLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统日志
 *
 * @author hanyx
 * @date 2019-06-05 10:07:31
 */
@RestController
@AllArgsConstructor
@RequestMapping("/opt-log")
@Api(value = "/opt-log", tags = {"UPMS-系统操作日志"})
@Slf4j
public class OptLogController {

    private final SysOptLogService optLogService;

    /**
     * 简单分页查询
     *
     * @param page     分页对象
     * @param optLogVO 系统日志
     * @return
     */
    @ApiOperation(value = "简单分页查询")
    @GetMapping("/page")
    public R<IPage<OptLogVO>> getOptLogPage(Page<OptLogVO> page, OptLogVO optLogVO) {
        return new R<>(optLogService.getOptLogPage(page, optLogVO));
    }


    /**
     * 通过id查询单条记录
     *
     * @param uuid
     * @return R
     */
    @ApiOperation(value = "通过id查询单条记录")
    @GetMapping("/{uuid}")
    public R<SysOptLog> getById(@PathVariable("uuid") String uuid) {
        if (StringUtils.isBlank(uuid)) {
            return R.buildError("ID不能为空");
        }
        return new R<>(optLogService.getById(uuid));
    }

}
